/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ytmc.downloader;

import java.net.MalformedURLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import ytmc.Controller;
import ytmc.View;

/**
 *
 * @author K
 */
public class DownloaderController implements Controller
{
    private DownloaderModel model;
    private DownloaderView view;

    public DownloaderController()
    {
        this.model = new DownloaderModel();
        this.view = new DownloaderView(this, model);
    }

    public void addTask()
    {
        try
        {
            DownloadTask task = new DownloadTask(view.getDownloadURL(), view.getSavePath());
            model.addTask(task);
        }
        catch (MalformedURLException ex)
        {
            view.showMessage(ex.getMessage());
            Logger.getLogger(DownloaderModel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
            
    public void removeTask(int index)
    {
        model.removeTask(index);
    }

    public void startTask(int index)
    {
        model.startTask(index);
    }

    @Override
    public View getView()
    {
        return view;
    }
}
